
app.directive('starttime',function(){
    return{
        restrict:'E',
        template: '<input type="text" style="font-size:14px;width: 100px;margin: 0 auto; position: relative; " class="form-control timemodel" ng-value="starttime" id="starttime">',
        replace:true,
        link:function(scope,element,attr){
            $(function(){
                   var nowData = new Date();    
                    element.val(nowData.toLocaleDateString());
                    element.ECalendar({
                    type:"date",
                    skin:"#233",
                    offset:[0,2]
                });
            })
        }
    }
});
app.directive('endtime',function(){
    return{
        restrict:'E',
        template: '<input type="text" style="font-size:14px;width: 100px; position: relative;" class="form-control timemodel" ng-model="endtime" id="endtime">',
        replace:true,
        link:function(scope,element,attr){
            $(function(){
                    var nowData = new Date();    
                    element.val(nowData.toLocaleDateString());
                    element.ECalendar({
                    type:"date",
                    skin:"#233",
                    offset:[0,2]
                });
            })
        }
    }
});
//入职日期
app.directive('stafftime',function(){
    return{
        restrict:'E',
        template: '<input type="text" id="date_entry" style="font-size:14px;position: relative; " class="form-control timemodel" ng-value="date_entry" >',
        replace:true,
        link:function(scope,element,attr){
            $(function(){
                var nowData = new Date();
                element.val(nowData.toLocaleDateString());
                element.ECalendar({
                    type:"date",
                    skin:"#233",
                    offset:[0,2]
                });
            })
        }
    }
});
// 离职日期
app.directive('outtime',function(){
    return{
        restrict:'E',
        template: '<input type="text" id="out_entry" style="font-size:14px;position: relative; " class="form-control timemodel" value="">',
        replace:true,
        link:function(scope,element,attr){
            $(function(){
                var nowData = new Date();
                element.val(nowData.toLocaleDateString());
                element.ECalendar({
                    type:"date",
                    skin:"#233",
                    offset:[0,2]
                });
            })
        }
    }
});
// 修改上课时间
app.directive('endclasstime',function(){
    return{
        restrict:'E',
        template: '<input type="text" style="font-size:14px;width: 120px; position: relative;margin: 0 auto;" class="form-control timemodel" id="endclasstime">',
        replace:true,
        link:function(scope,element,attr){
            $(function(){
                    element.ECalendar({
                    type:"date",
                    skin:"#233",
                    offset:[0,2]
                });
            })
        }
    }
});



// 缴费记录查找日期
app.directive('modeltime',function(){
    return{
        restrict:'E',
        template: '<input type="text" style="font-size:14px;width: 100px; position: relative;" class="form-control timemodel" ng-model="modeltime" id="modeltime">',
        replace:true,
        link:function(scope,element,attr){
            $(function(){
                    element.ECalendar({
                    type:"date",
                    skin:"#233",
                    offset:[0,2]
                });
            })
        }
    }
});

app.directive('modeltimetwo',function(){
    return{
        restrict:'E',
        template: '<input type="text" style="font-size:14px;width: 186px; position: relative;" class="form-control timemodel" ng-model="modeltimetwo" id="modeltimetwo">',
        replace:true,
        link:function(scope,element,attr){
            $(function(){
                    element.ECalendar({
                    type:"date",
                    skin:"#233",
                    offset:[0,2]
                });
            })
        }
    }
});
// 时间段组件 上课时间
app.directive("haveclockpicker",function () {
    return{
        restrict:'E',
        template:'<div class="input-group clockpicker"  id="haveclass" style="width: 140px;margin: 0 auto;">\n' +
        '    <input type="text" class="form-control" value="09:30" id="haveclockpicker">\n' +
        '    <span class="input-group-addon">\n' +
        '        <span class="glyphicon glyphicon-time"></span>\n' +
        '    </span>\n' +
        '</div>',
        replace:true,
        link:function (scope,element,attr) {
            $('#haveclass').clockpicker();
        }
    }
})
// 时间段组件 下课时间
app.directive("overclockpicker",function () {
    return{
        restrict:'E',
        template:'<div class="input-group clockpicker"  id="overclass" style="width: 140px;margin: 0 auto;">\n' +
        '    <input type="text" class="form-control" value="11:30" id="overclockpicker">\n' +
        '    <span class="input-group-addon">\n' +
        '        <span class="glyphicon glyphicon-time"></span>\n' +
        '    </span>\n' +
        '</div>',
        replace:true,
        link:function (scope,element,attr) {
            $('#overclass').clockpicker();
        }
    }
})
// 修改时间段组件 上课时间
app.directive("updatahaveclockpicker",function () {
    return{
        restrict:'E',
        template:'<div class="input-group clockpicker"  id="updatahaveclass" style="width: 140px;margin: 0 auto;">\n' +
        '    <input type="text" class="form-control" value="{{prod.class_time_have|limitTo:5}}" id="updatahaveclockpicker">\n' +
        '    <span class="input-group-addon">\n' +
        '        <span class="glyphicon glyphicon-time"></span>\n' +
        '    </span>\n' +
        '</div>',
        replace:true,
        link:function (scope,element,attr) {
            $('#updatahaveclass').clockpicker();
        }
    }
})
// 修改时间段组件 下课时间
app.directive("updataoverclockpicker",function () {
    return{
        restrict:'E',
        template:'<div class="input-group clockpicker"  id="updataoverclass" style="width: 140px;margin: 0 auto;">\n' +
        '    <input type="text" class="form-control" value="{{prod.class_time_over|limitTo:5}}" id="updataoverclockpicker">\n' +
        '    <span class="input-group-addon">\n' +
        '        <span class="glyphicon glyphicon-time"></span>\n' +
        '    </span>\n' +
        '</div>',
        replace:true,
        link:function (scope,element,attr) {
            $('#updataoverclass').clockpicker();
        }
    }
})


// 校区组件
app.directive('schoolcampus',function(){
     return{
        restrict:'E',
        template: '<select  class="tankuang"  id="schoolcampus"></select>',
        replace:true,
        link:function(scope,element,attr){
            var token=getCookie('token');
            $(function(){
                     var url="/OA/campus/list";
                       $.ajax({
                           type: "GET",
                           url: url,
                           dataType:"json",
                           data:{id:token},
                           success:function (response) {
                               element.append('<option  selected  value="0">'+"全部校区"+'</option>')
                               for (var i = 0; i < response.data.length; i++) {
                                   element.append('<option value='+response.data[i].id+'>'+response.data[i].name+'</option>')
                               };
                               $("#schoolcampus option[value='? undefined:undefined ?']").remove();
                           }
                       })
            })
        }
    }   
})

//
// 所教科目
app.directive('subjectstaught',function(){
    return{
        restrict:'E',
        template: '<select  class="tankuang"  id="subjectstaught"></select>',
        replace:true,
        link:function(scope,element,attr){
            var token=getCookie('token');
            $(function(){
                var url="/OA/subject/list";
                $.ajax({
                    type: "GET",
                    url: url,
                    dataType:"json",
                    success:function (response) {
                        element.append('<option disabled selected style="display: none;" value="0">'+"选择科目"+'</option>')
                        for (var i = 0; i < response.data.length; i++) {
                            element.append('<option value='+response.data[i].id+'>'+response.data[i].name+'</option>')
                        };
                        $("#subjectstaught option[value='? undefined:undefined ?']").remove();
                    }
                })
            })
        }
    }
})
// 一对一排课
// 2017 10/2
// 根据科目选择老师
app.directive('subjectteacher',function(){
    return{
        restrict:'E',
        template: '<select  class="tankuang-tf"  id="subjectteacher"></select>',
        replace:true,
        link:function(scope,element,attr){
            var token=getCookie('token');
            $(function(){
                var url="/OA/subject/list";
                $.ajax({
                    type: "GET",
                    url: url,
                    dataType:"json",
                    success:function (response) {
                        element.append('<option disabled selected style="display: none;" value="0">'+"选择科目"+'</option>')
                        for (var i = 0; i < response.data.length; i++) {
                            element.append('<option value='+response.data[i].id+'>'+response.data[i].name+'</option>')
                        };
                        $("#subjectteacher option[value='? undefined:undefined ?']").remove();
                        // 选择切换
                        $("#subjectteacher").change(function () {
                             var subject_id=$(this).val();
                             $.ajax({
                                 type:"POST",
                                 url:"/OA/staff/find?role_id=8",
                                 data:{subject_id:subject_id,is_class:"all"},
                                 dataType:"json",
                                 success:function (result) {
                                     $("#teacher").html("");
                                     for (var i = 0; i < result.data.length; i++) {
                                         $("#teacher").append('<option value='+result.data[i].id+'>'+result.data[i].username+'</option>')
                                     };
                                 }
                             })
                        })
                    }
                })
            })
        }
    }
})
// 一对一排课修改
// 根据科目选择老师
app.directive('subjectupdatateacher',function(){
    return{
        restrict:'E',
        template: '<select  class="tankuang-tf"  id="subjectupdatateacher"></select>',
        replace:true,
        link:function(scope,element,attr){
            var token=getCookie('token');
            $(function(){
                var url="/OA/subject/list";
                $.ajax({
                    type: "GET",
                    url: url,
                    dataType:"json",
                    success:function (response) {
                        for (var i = 0; i < response.data.length; i++) {
                            element.append('<option value='+response.data[i].id+'>'+response.data[i].name+'</option>')
                        };
                        $("#subjectupdatateacher option[value='? undefined:undefined ?']").remove();
                        // 选择切换
                        $("#subjectupdatateacher").change(function () {
                            var subject_id=$(this).val();
                            $.ajax({
                                type:"POST",
                                url:"/OA/staff/find?role_id=8",
                                data:{subject_id:subject_id,is_class:"all"},
                                dataType:"json",
                                success:function (result) {
                                    $("#teacherupdata").html("");
                                    for (var i = 0; i < result.data.length; i++) {
                                        $("#teacherupdata").append('<option value='+result.data[i].id+'>'+result.data[i].username+'</option>')
                                    };
                                }
                            })
                        })
                    }
                })
            })
        }
    }
})

// 所选科目修改
app.directive('subjectname',function(){
    return{
        restrict:'E',
        template: '<select  class="tankuang"  id="subjectname"></select>',
        replace:true,
        link:function(scope,element,attr){
            var token=getCookie('token');
            $(function(){
                var url="/OA/subject/list";
                $.ajax({
                    type: "GET",
                    url: url,
                    dataType:"json",
                    success:function (response) {
                        element.append('<option disabled selected style="display: none;" value="0">'+"选择科目"+'</option>')
                        for (var i = 0; i < response.data.length; i++) {
                            element.append('<option value='+response.data[i].id+'>'+response.data[i].name+'</option>')
                        };
                        $("#subjectname option[value='? undefined:undefined ?']").remove();
                    }
                })
            })
        }
    }
})
//  所属校区   notice  员工设置修改
app.directive('belongeschool',function(){
    return{
        restrict:'E',
        template: '<select  class="tankuang" ng-model="belongeschool" id="belongeschool"></select>',
        replace:true,
        link:function(scope,element,attr){
            var token=getCookie('token');
            $(function(){
                var url="/OA/campus/list";
                $.ajax({
                    type: "GET",
                    url: url,
                    dataType:"json",
                    data:{id:token},
                    success:function (response) {
                        element.append('<option disabled selected style="display: none;" value="0">'+"选择校区"+'</option>')
                        for (var i = 0; i < response.data.length; i++) {
                            element.append('<option value='+response.data[i].id+'>'+response.data[i].name+'</option>')
                        };
                        $("#belongeschool option[value='? undefined:undefined ?']").remove();
                    }
                })
            })
        }
    }
})

// 2017 7 27
// Create guohongjun
// 修改校区文本框

app.directive('modifyschool',function(){
     return{
        restrict:'E',
        template: '<select style="border:none; " class="bgColorOption" ng-model="modifyschool" id="modifyschool"></select>',
        replace:true,
        link:function(scope,element,attr){
            $(function(){
                     var url="/OA/campus/list";
                       $.get(url, function(response){
                           // var optionDom=element.append('<option disabled selected style="display: none;" value="">'+"校区"+'</option>')
                              for (var i = 0; i < response.data.length; i++) {
                                    element.append('<option value='+response.data[i].id+'>'+response.data[i].name+'</option>')
                                };
                                $("#modifyschool option[value='? undefined:undefined ?']").remove();  
                                $("#modifyschool option[value='1']").attr("selected","selected")
                            });
            })
        }
    }   
})


// 2017 7 28
//职位组件
// Create  guohongjun
app.directive('chooseposition',function(){
     return{
        restrict:'E',
        template: '<select class="tankuang" style="height:32px;width:100px;border-radius:4px;border:solid 1px #ccc;margin-left: 10px;"  ng-model="choosePosition" id="choosePosition"></select>',
        replace:true,
        link:function(scope,element,attr){
            $(function(){
                     var url="/OA/role/list";
                       $.get(url, function(response){
                             element.append('<option disabled selected style="display: none;" value="0">'+"职位"+'</option>')
                              for (var i = 0; i < response.data.length; i++) {
                                    element.append('<option value='+response.data[i].id+'>'+response.data[i].name+'</option>')
                                };
                                $("#choosePosition option[value='? undefined:undefined ?']").remove();  
                            });
            })
        }
    }   
})
// 2017 9/21
//复选职位
//Create guohongjun
app.directive('moreroles',function(){
     return{
        restrict:'E',
        template: '<ul></ul>',
        replace:true,
        link:function(scope,element,attr){
            $(function(){
                     var url="/OA/role/list";
                     var token=getCookie('token');
                       $.get(url,{id:token}, function(response){
                           console.log(response)
                              for (var i = 0; i < response.data.length; i++) {
                                    element.append('<li class="option">'+'<input class="case" name="checkbox" type="checkbox">'+'<a href="javascript:;">'+response.data[i].role_value+','+'</a>'+'<span style="font-size:0px;" id="responseId">'+response.data[i].id+','+'<span>'+'</li>')
                                };
    //显示\隐藏下拉菜单
    $(".dropdown-menu").hide();
    $("#updatarole").click(function () {
        $("#updata-menu").show();
    });
    $("#staffName").click(function () {
        $("#staff-menu").show()
    })
    $(".okcheck .a1").click(function() {
        var str = $("input:checkbox[name='checkbox']:checked").next().text();
        var strHtml=$("input:checkbox[name='checkbox']:checked").next().next().text();
        //var str = '';
        $("input:checkbox[name='checkbox']:checked").each(function() {
            str = str;
            strHtml=strHtml;
            str=(str.substring(str.length-1)==',')?str.substring(0,str.length-1):str;
            strHtml=(strHtml.substring(strHtml.length-1)==',')?strHtml.substring(0,strHtml.length-1):strHtml;
        });
        console.log(str);
        console.log(strHtml);
        $("#staffName").html(str);
        $("#staffIdName").html(strHtml);
        $(".dropdown-menu").hide();
    });
    $(".okcheck .a2").click(function() {
        $(".dropdown-menu").hide();
    });

    $(".case").change(function() {
        var i = 0;
        $("input:checkbox[name='checkbox']:checked").each(function() {
            i++;
        });
        $("#count").html(i);
    });
 });
})
}
}     
})
// 修改复选职位
app.directive('updataroles',function(){
    return{
        restrict:'E',
        template: '<ul></ul>',
        replace:true,
        link:function(scope,element,attr){
            $(function(){
                var url="/OA/role/list";
                var token=getCookie('token');
                $.get(url,{id:token}, function(response){
                    for (var i = 0; i < response.data.length; i++) {
                        element.append('<li class="option">'+'<input class="case" name="check" type="checkbox">'+'<a href="javascript:;">'+response.data[i].role_value+','+'</a>'+'<span style="font-size:0px;" id="responseId">'+response.data[i].id+','+'<span>'+'</li>')
                    };
                    //显示\隐藏下拉菜单
                    $(".dropdown-menu").hide();
                    $("#updatarole").click(function () {
                        $("#updata-menu").show();
                    });
                    $("#staffName").click(function () {
                        $("#staff-menu").show()
                    })
                    $(".okcheck .a1").click(function() {
                        var str = $("input:checkbox[name='check']:checked").next().text();
                        var strHtml=$("input:checkbox[name='check']:checked").next().next().text();
                        //var str = '';
                        $("input:checkbox[name='check']:checked").each(function() {
                            str = str;
                            strHtml=strHtml;
                            str=(str.substring(str.length-1)==',')?str.substring(0,str.length-1):str;
                            strHtml=(strHtml.substring(strHtml.length-1)==',')?strHtml.substring(0,strHtml.length-1):strHtml;
                        });
                        console.log(str);
                        console.log(strHtml);
                        $("#updatarole").html(str);
                        $("#updataId").html(strHtml);
                        $(".dropdown-menu").hide();
                    });
                    $(".okcheck .a2").click(function() {
                        $(".dropdown-menu").hide();
                    });

                    $(".case").change(function() {
                        var i = 0;
                        $("input:checkbox[name='check']:checked").each(function() {
                            i++;
                        });
                        $("#count").html(i);
                    });
                });
            })
        }
    }
})
// 2017 7/ 29  
// Create :郭鸿君
// 封装 滚动条组件
app.directive('niceScroll', function(){
    return {
        link: function($scope, ele, attrs){
                ele.niceScroll({  
                cursorcolor:"#CC0071",  
                cursoropacitymax:1,  
                touchbehavior:false,
                cursorwidth:"0",
                cursorborder:"0",  
                cursorborderradius:"5px"  
             }); 
        }
    };
});

//一对一日历组件
// 2017 7 /29 
app.directive('calendar',function(){
    return{
        restrict:'E',
        template: '<div id="calendar" class="calendar"></div>',
        replace:true,
        link:function(scope,element,attr){
                }
           }
});
// 2017 / 7/ 31
// 获取员工所有职位
//郭鸿君
app.directive('teacherschool',function(){
    return{
        restrict:'E',
        template: ' <select class="tankuang" style="height:32px;width:100px;border-radius:4px;border:solid 1px #ccc;margin-left: 10px;"  ng-model="teacherschool" id="teacherschool"></select>',
        replace:true,
        link:function(scope,element,attr){
            $(function(){
                var url="/OA/role/list";
                $.get(url, function(response){
                    element.append('<option disabled selected style="display: none;" value="0">'+"职位"+'</option>');
                    for(var i=0 ;i< response.data.length;i++){
                        element.append('<option value='+response.data[i].id+'>'+response.data[i].name+'</option>')
                    }
                    $("#teacherschool option[value='? undefined:undefined ?']").remove();
                });
            })
        }
    }
})
//缴费方式
app.directive('methostyle',function(){
    return{
        restrict:'E',
        template: ' <select class="tankuang" style="width: 100%;" id="methostyle"></select>',
        replace:true,
        link:function(scope,element,attr){
            $(function(){
                var url="/OA/method/list";
                $.get(url, function(response){
                    element.append('<option disabled selected style="display: none;" value="0">'+"缴费方式"+'</option>');
                    for(var i=0 ;i< response.data.length;i++){
                        element.append('<option value='+response.data[i].id+'>'+response.data[i].name+'</option>')
                    }
                    $("#methostyle option[value='? undefined:undefined ?']").remove();
                });
            })
        }
    }
})
// 补交缴费方式
app.directive('methodstyle',function(){
    return{
        restrict:'E',
        template: ' <select class="tankuang" style="width: 100%;" id="methodstyle"></select>',
        replace:true,
        link:function(scope,element,attr){
            $(function(){
                var url="/OA/method/list";
                $.get(url, function(response){
                    element.append('<option disabled selected style="display: none;" value="">'+""+'</option>');
                    for(var i=0 ;i< response.data.length;i++){
                        element.append('<option value='+response.data[i].id+'>'+response.data[i].name+'</option>')
                    }
                    $("#methodstyle option[value='? undefined:undefined ?']").remove();
                });
            })
        }
    }
})

// 分页组件
app.factory('myPage',function () {
    var f={};
    f.pageNub=1;
    f.getPageNub=function () {
        return f.pageNub;
    };
    f.setPageNub=function (n) {
        f.pageNub=n;
    };
    return f;
    console.log(f)
});
app.directive('myPagination',['myPage',function (myPage) {
    return {
        restrict:'EA',
        replace:true,
        template:'<div class="my-page">\
                            <div class="page">\
                                 <span class="page-list" ng-class="{disabled: pg.currentPage == 1}" ng-click="prevPage()">&#171;</span>\
                                 <span class="page-list" ng-class="{active:item==pg.currentPage,borderNone:item==\'...\'}" ng-click="changeCurrentPage(item)" ng-repeat="item in pageList track by $index">{{item}}</span>\
                                 <span class="page-list" ng-class="{disabled: pg.currentPage == pg.numberOfPages}" ng-click="nextPage()">&#187;</span>\
                             </div>\
                             <div class="goPage">\
                                 <span >第<input type="number" ng-model="pg.jumpPageNum"  ng-change="jumpToPage()"/>页</span>\
                                 <span style="display:none">每页<select name="" id="" ng-model="pg.itemsPerPage" ng-options="option for option in pg.perPageOptions " ng-change="changeItemsPerPage()"></select>条/</span>\
                                 <span>共{{pg.totalItems}}条</span>\
                             </div>\
                             <div ng-if="pg.showError">请输入正确页码</div>\
                         </div>',
        scope:{
            pg:'='
        },
        link: function(scope, element, attrs){
            // ng-show="pg.totalItems > pg.itemsPerPage"
            // 变更当前页
            scope.pg.currentPage=myPage.pageNub;
            scope.changeCurrentPage = function(p){
                if(p == '...'){
                    return;
                }else{
                    scope.pg.currentPage = p;
                    myPage.setPageNub(scope.pg.currentPage);
                }
                getPagination();
            };
            scope.prevPage = function(){
                if(scope.pg.currentPage > 1){
                    scope.pg.currentPage -= 1;
                }else {
                    scope.pg.currentPage=1;
                }
                myPage.setPageNub(scope.pg.currentPage);
                getPagination();
            };
            // nextPage
            scope.nextPage = function(){
                if(scope.pg.currentPage < scope.pg.numberOfPages){
                    scope.pg.currentPage += 1;
                }else {
                    scope.pg.currentPage=scope.pg.numberOfPages;
                }
                myPage.setPageNub(scope.pg.currentPage);
                getPagination()
            };

            // 跳转页
            scope.jumpToPage = function(){
                if(scope.pg.jumpPageNum>0 || scope.pg.jumpPageNum<=scope.pg.numberOfPages){
                    scope.pg.currentPage=scope.pg.jumpPageNum;
                    myPage.setPageNub(scope.pg.currentPage);
                    getPagination();
                    scope.pg.jumpPageNum='';
                }else {
                    scope.pg.showError=true;
                }
            };

            // 修改每页显示的条数
            scope.changeItemsPerPage = function(){
                getPagination();
            };

            // 定义分页的长度必须为奇数 (default:9)
            scope.pg.pagesLength = parseInt(scope.pg.pagesLength) ? parseInt(scope.pg.pagesLength) : 9 ;
            if(scope.pg.pagesLength % 2 === 0){
                // 如果不是奇数的时候处理一下
                scope.pg.pagesLength = scope.pg.pagesLength -1;
            }

            // pg.erPageOptions
            if(!scope.pg.perPageOptions){
                scope.pg.perPageOptions = [10, 15, 20, 30, 50];
            }

            // pageList数组
            getPagination();
            function getPagination(){
                // pg.currentPage
                scope.pg.currentPage = parseInt(myPage.pageNub);
                console.log(scope.pg.currentPage);
                // pg.totalItems
                scope.pg.totalItems = parseInt(scope.pg.totalItems);

                // numberOfPages,总共分多少页
                scope.pg.numberOfPages = Math.ceil(scope.pg.totalItems/scope.pg.itemsPerPage);

                // judge currentPage > scope.numberOfPages
                if(scope.pg.currentPage < 1){
                    scope.pg.currentPage = 1;
                }

                if(scope.pg.currentPage > scope.pg.numberOfPages){
                    scope.pg.currentPage = scope.pg.numberOfPages;
                }


                scope.pageList = [];
                if(scope.pg.numberOfPages <= scope.pg.pagesLength){
                    // 判断总页数如果小于等于分页的长度，若小于则直接显示
                    for(i =1; i <= scope.pg.numberOfPages; i++){
                        scope.pageList.push(i);
                    }
                }else{
                    // 总页数大于分页长度（此时分为三种情况：1.左边没有...2.右边没有...3.左右都有...）
                    // 计算中心偏移量
                    var offset = (scope.pg.pagesLength - 1)/2;
                    if(scope.pg.currentPage <= offset){
                        // 左边没有...
                        for(i =1; i <= offset +1; i++){
                            scope.pageList.push(i);
                        }
                        scope.pageList.push('...');
                        scope.pageList.push(scope.pg.numberOfPages);
                        //    >实际总页数-每页的一半
                    }else if(scope.pg.currentPage > scope.pg.numberOfPages - offset){
                        scope.pageList.push(1);
                        scope.pageList.push('...');
                        for(i = offset + 1; i >= 1; i--){
                            scope.pageList.push(scope.pg.numberOfPages - i);
                        }
                        scope.pageList.push(scope.pg.numberOfPages);
                    }else{
                        // 最后一种情况，两边都有...
                        scope.pageList.push(1);
                        scope.pageList.push('...');

                        for(i = Math.ceil(offset/2) ; i >= 1; i--){
                            scope.pageList.push(scope.pg.currentPage - i);
                        }
                        scope.pageList.push(scope.pg.currentPage);
                        for(i = 1; i <= offset/2; i++){
                            scope.pageList.push(scope.pg.currentPage + i);
                        }

                        scope.pageList.push('...');
                        scope.pageList.push(scope.pg.numberOfPages);
                    }
                }
                console.log(scope.pageList)
            }

        }
    }
}]);
// 联动复选老师科目
// 2017 9 、26
app.directive('subjectusername',function(){
    return{
        restrict:'E',
        template: '<select class="tankuang-classsubject" id="subjectoption"></select>',
        replace:true,
        link:function(scope,element,attr){
            $(function(){
                var url="/OA/subject/list";
                $.get(url, function(response){
                    element.append('<option disabled selected style="display: none;" value="0">'+"请选择"+'</option>');
                    for(var i=0 ;i< response.data.length;i++){
                        element.append('<option value='+response.data[i].id+'>'+response.data[i].name+'</option>')
                    }
                    $("#subjectoption option[value='? undefined:undefined ?']").remove();
                     $("#subjectoption").change(function(){
                         var subjectnameval=$(this).val();
                         $.ajax({
                             type: "POST",
                             url: "/OA/staff/find",
                             dataType:"json",
                             data:{role_id:8,subject_id:subjectnameval},
                             success:function (response) {
                                 $("#subjectteacher").html("");
                                 $("#subjectteacher").append('<option disabled selected style="display: none;" value="0">'+"请选择"+'</option>')
                                 for (var i = 0; i < response.data.length; i++) {
                                     $("#subjectteacher").append('<option value='+response.data[i].id+'>'+response.data[i].username+'</option>')
                                 };
                                 $("#subjectteacher option[value='? undefined:undefined ?']").remove();
                             }
                         });
                         // 二级科目
                         $.ajax({
                             type: "POST",
                             url: "/OA/subject/list?type=2",
                             dataType:"json",
                             data:{parent_id:subjectnameval},
                             success:function (response) {
                                 $("#twosubject").html("");
                                 $("#twosubject").append('<option disabled selected style="display: none;" value="0">'+"请选择"+'</option>')
                                 for (var i = 0; i < response.data.length; i++) {
                                     $("#twosubject").append('<option value='+response.data[i].id+'>'+response.data[i].name+'</option>')
                                 };
                                 $("#twosubject option[value='? undefined:undefined ?']").remove();
                             }
                         });

                     })
                });
            })
        }
    }
})
// 学员招生栏
// 2017 9/27
// 咨询
app.directive('consulting',function(){
    return{
        restrict:'E',
        template: '<select class="tankuang" style="border-radius:4px;border:solid 1px #ccc;"  id="consulting"></select>',
        replace:true,
        link:function(scope,element,attr){
            $(function(){
                var url="/OA/staff/find?role_id=1"
                $.get(url, function(response){
                    element.append('<option disabled selected style="display: none;" value="">'+""+'</option>')
                    for (var i = 0; i < response.data.length; i++) {
                        element.append('<option value='+response.data[i].id+'>'+response.data[i].username+'</option>')
                    };
                    $("#choosePosition option[value='? undefined:undefined ?']").remove();
                });
            })
        }
    }
})
// 教务
app.directive('administration',function(){
    return{
        restrict:'E',
        template: '<select class="tankuang" style="border-radius:4px;border:solid 1px #ccc;"  id="administration"></select>',
        replace:true,
        link:function(scope,element,attr){
            $(function(){
                var url="/OA/staff/find?role_id=3"
                $.get(url, function(response){
                    element.append('<option disabled selected style="display: none;" value="">'+""+'</option>')
                    for (var i = 0; i < response.data.length; i++) {
                        element.append('<option value='+response.data[i].id+'>'+response.data[i].username+'</option>')
                    };
                    $("#choosePosition option[value='? undefined:undefined ?']").remove();
                });
            })
        }
    }
})
// 获取年级
// Create  guohongjun
app.directive('grade',function(){
    return{
        restrict:'E',
        template: ' <select class="tankuang" id="grade"></select>',
        replace:true,
        link:function(scope,element,attr){
            $(function(){
                var url="/OA/grade/list";
                $.get(url, function(response){
                    element.append('<option disabled selected style="display: none;">'+"年级"+'</option>');
                    for(var i=0 ;i< response.data.length;i++){
                        element.append('<option value='+response.data[i].id+'>'+response.data[i].name+'</option>')
                    }
                    $("#grade option[value='? undefined:undefined ?']").remove();
                });
            })
        }
    }
})
//修改年级
app.directive('updatagrade',function(){
    return{
        restrict:'E',
        template: ' <select class="tankuang" id="updatagrade"></select>',
        replace:true,
        link:function(scope,element,attr){
            $(function(){
                var url="/OA/grade/list";
                $.get(url, function(response){
                    element.append('<option disabled selected style="display: none;">'+"年级"+'</option>');
                    for(var i=0 ;i< response.data.length;i++){
                        element.append('<option value='+response.data[i].id+'>'+response.data[i].name+'</option>')
                    }
                    $("#updatagrade option[value='? undefined:undefined ?']").remove();
                });
            })
        }
    }
})
// 修改咨询
app.directive('updataconsulting',function(){
    return{
        restrict:'E',
        template: '<select class="tankuang" style="border-radius:4px;border:solid 1px #ccc;"  id="updataconsulting"></select>',
        replace:true,
        link:function(scope,element,attr){
            $(function(){
                var url="/OA/staff/find?role_id=1"
                $.get(url, function(response){
                    element.append('<option  value="">'+""+'</option>')
                    for (var i = 0; i < response.data.length; i++) {
                        element.append('<option value='+response.data[i].id+'>'+response.data[i].username+'</option>')
                    };
                    $("#updataconsulting option[value='? undefined:undefined ?']").remove();
                });
            })
        }
    }
})
//修改教务
app.directive('updataadministration',function(){
    return{
        restrict:'E',
        template: '<select class="tankuang" style="border-radius:4px;border:solid 1px #ccc;"  id="updataadministration"></select>',
        replace:true,
        link:function(scope,element,attr){
            $(function(){
                var url="/OA/staff/find?role_id=3"
                $.get(url, function(response){
                    element.append('<option  value="">'+""+'</option>')
                    for (var i = 0; i < response.data.length; i++) {
                        element.append('<option value='+response.data[i].id+'>'+response.data[i].username+'</option>')
                    };
                    $("#updataadministration option[value='? undefined:undefined ?']").remove();
                });
            })
        }
    }
})
//负责人
app.directive('responsible',function(){
    return{
        restrict:'E',
        template: '<select class="search-content" style="background:#ebe0f9;text-align: center;font-size: 14px;"  id="responsible"></select>',
        replace:true,
        link:function(scope,element,attr){
            $(function(){
                var url="/OA/staff/find"
                $.get(url, function(response){
                    element.append('<option disabled selected style="display: none; text-align: center;font-size: 14px;" value="">'+"负责人"+'</option>');
                    element.append('<option  style="text-align: center;font-size: 14px;" value="">'+"全部"+'</option>');
                    for (var i = 0; i < response.data.length; i++) {
                        element.append('<option value='+response.data[i].id+' >'+response.data[i].username+'</option>')
                    };
                    $("#responsible option[value='? undefined:undefined ?']").remove();
                });
            })
        }
    }
})
// 班级课表 班级合同创建合同
app.directive('createclass',function(){
    return{
        restrict:'E',
        template: '<select class="tankuang"  id="createclass"></select>',
        replace:true,
        link:function(scope,element,attr){
            $(function(){
                var url="/OA/class/list"
                $.get(url, function(response){
                    element.append('<option disabled selected style="display: none; text-align: center;font-size: 14px;" value="">'+"选择班级"+'</option>')
                    for (var i = 0; i < response.data.length; i++) {
                        element.append('<option value='+response.data[i].id+' >'+response.data[i].name+'</option>')
                    };
                    $("#createclass option[value='? undefined:undefined ?']").remove();
                });
            })
        }
    }
})
// 班课排课切换班级
app.directive('createclasshtml',function(){
    return{
        restrict:'E',
        template: '<select class="tankuang"  id="createclasshtml"></select>',
        replace:true,
        link:function(scope,element,attr){
            $(function(){
                var url="/OA/class/list"
                $.get(url, function(response){
                    element.append('<option disabled selected style="display: none; text-align: center;font-size: 14px;" value="">'+"选择班级"+'</option>')
                    for (var i = 0; i < response.data.length; i++) {
                        element.append('<option value='+response.data[i].id+' >'+response.data[i].name+'</option>')
                    };
                    $("#createclasshtml option[value='? undefined:undefined ?']").remove();
                });
            })
        }
    }
})
//享受优惠政策  一对一
app.directive('saleone2one',function(){
    return{
        restrict:'E',
        template: '<select class="tankuang-discount"  id="saleone2one"></select>',
        replace:true,
        link:function(scope,element,attr){
            $(function(){
                var url="/OA/saleone2one/list"
                $.get(url, function(response){
                    element.append('<option disabled selected style="display: none; text-align: center;font-size: 14px;" value="">'+"选择优惠"+'</option>');
                    element.append('<option  style=" text-align: center;font-size: 14px;" value="">'+"无优惠政策"+'</option>');
                    for (var i = 0; i < response.data.length; i++) {
                        element.append('<option data='+response.data[i].hour+' value='+response.data[i].id+' >'+response.data[i].name+'</option>')
                    };
                    $("#saleone2one option[value='? undefined:undefined ?']").remove();
                });
            })
        }
    }
})

app.directive('saleclass',function(){
    return{
        restrict:'E',
        template: '<select class="tankuang-discount"  id="saleclass"></select>',
        replace:true,
        link:function(scope,element,attr){
            $(function(){
                var url="/OA/saleclazz/list"
                $.get(url, function(response){
                    element.append('<option disabled selected style="display: none; text-align: center;font-size: 14px;" value="">'+"选择优惠"+'</option>');
                    for (var i = 0; i < response.data.length; i++) {
                        element.append('<option data='+response.data[i].sale+' value='+response.data[i].id+' >'+response.data[i].name+'</option>')
                    };
                    $("#saleclass option[value='? undefined:undefined ?']").remove();
                });
            })
        }
    }
})